import { Init, Provide } from '@midwayjs/decorator';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { WallpaperImageInfoEntity } from '../entity/image_info';

/**
 * wallpaper模块-图片信息服务
 */
@Provide()
export class WallpaperImageInfoService extends BaseService {
  @InjectEntityModel(WallpaperImageInfoEntity)
  wallpaperImageInfoEntity: Repository<WallpaperImageInfoEntity>;

  @Init()
  async init() {
    await super.init();
    this.setEntity(this.wallpaperImageInfoEntity);
  }

  /**
   * 根据分类获取图片信息
   * @param category 分类
   */
  async getImagesByCategory(category: string) {
    return this.wallpaperImageInfoEntity.findBy({ category, status: 1 });
  }
}
